using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Microblaze.Simulator.Engine;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    public class Get : Instruction
    {
        private enum GetInstructionKind
        {
            None,
            get,
            nget,
            cget,
            ncget
        }

        private GetInstructionKind kind;

        public override int CycleCount
        {
            get { return 2; }
        }

        public Get()
            : base("get")
        {
        }

        public uint Fls
        {
            get { return Value & 0x00000007; }
        }

        public override void Set(uint address, uint value)
        {
            base.Set(address, value);

            uint sub_opcode = value & 0x0000F000;

            kind =
              (sub_opcode == 0x00000000) ? GetInstructionKind.get :
              (sub_opcode == 0x00004000) ? GetInstructionKind.nget :
              (sub_opcode == 0x00002000) ? GetInstructionKind.cget :
              (sub_opcode == 0x00006000) ? GetInstructionKind.ncget :
              GetInstructionKind.None;

            if (kind == GetInstructionKind.None)
                throw new UnknownInstructionException(value);
        }

        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override string ToString()
        {
            return string.Format("{0} r{1}, {2}",
              kind,
              DestinationRegister,
              Fls
            );
        }
    }
}
